package com.max.rabbitmq.learn.worker;

import com.max.rabbitmq.learn.util.ConnectionUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

/**
 * @description worker模式发送者
 * @author yandong
 * @create 2021年4月07日 09:13:40
 */
public class Send {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("max-host-worker-mode", true, false, false, null);

        String message = "hello world";
        for (int i = 0; i < 10; i++) {
            channel.basicPublish("", "max-host-worker-mode", new AMQP.BasicProperties().builder().messageId((i + 1) + "").build(), message.getBytes(StandardCharsets.UTF_8));
        }
        channel.close();
        connection.close();
    }
}
